package top.kpromise.user.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.kpromise.user.model.response.UserTicketModel;

@Repository
public interface UserTicketMapper {

    @Insert("insert into user_ticket (userId, type, ticket, updateAt) values (#{userId}, #{type}, #{ticket}, #{updateAt})")
    int insert(UserTicketModel userTicketModel);

    @Update("update user_ticket set ticket = #{ticket}, updateAt = #{updateAt} where userId = #{userId} " +
            "and type = #{type} limit 1")
    int update(UserTicketModel userTicketModel);

    @Select("select * from user_ticket where ticket = #{ticket} limit 1")
    UserTicketModel findByTicket(String ticket);

    @Select("select * from user_ticket where type = #{type} and userId = #{userId} limit 1")
    UserTicketModel findByUserIdAndType(String userId, int type);

    @Delete("delete from user_ticket where ticket = #{ticket} limit 1")
    int deleteByTicket(String ticket);
}
